//
//  growthDetailVController.m
//  SKaURobot
//
//  Created by cdong on 16/3/3.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "growthDetailVController.h"

@interface growthDetailVController ()

@property (nonatomic ,strong)UIButton *moreBtn;
@property (nonatomic ,strong)UIButton *backBtn;
@property (nonatomic ,strong)UILabel *navigationVL;
@property (nonatomic ,strong)UILabel *navigationUnderVL;
@property (nonatomic ,strong)UIView *navigationV;
@property (nonatomic ,strong)UIImageView *photoV;

@property (nonatomic ,strong)UIView *selectAllView;
@property (nonatomic ,strong)UIView *selectView;
@property (nonatomic ,strong)UIView *fillView;
@property (nonatomic ,strong)UIButton *deleteBtn;
@property (nonatomic ,strong)UIButton *cancelBestBtn;
@property (nonatomic ,strong)UIButton *storePicBtn;
@property (nonatomic ,strong)UIButton *sharePicBtn;
@property (nonatomic ,strong)UIButton *cancelBtn;

@property (nonatomic ,assign)BOOL selectedFlag;
@property (nonatomic ,assign)BOOL sharedFlag;

@property (nonatomic ,strong)UIView *shareView;
@property (nonatomic ,strong)UIView *shareUnderV;
@property (nonatomic ,strong)UIButton *weixinBtn;
@property (nonatomic ,strong)UIButton *firentBtn;
@property (nonatomic ,strong)UIButton *qqFriendBtn;
@property (nonatomic ,strong)UIButton *qqSpaceBtn;
@property (nonatomic ,strong)UIButton *cancelShareBtn;

@end

@implementation growthDetailVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x1a1a1b alpha:1];
    self.selectedFlag = NO;
    self.sharedFlag = NO;
    [self loadNavigationBg];
    [self loadPhotoV];
    [self loadSelectView];
    [self loadShareView];
    [self.backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.moreBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.deleteBtn addTarget:self action:@selector(deleteBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelBestBtn addTarget:self action:@selector(cancelBestBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.storePicBtn addTarget:self action:@selector(storePicBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.sharePicBtn addTarget:self action:@selector(sharePicBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelBtn addTarget:self action:@selector(cancelBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.cancelShareBtn addTarget:self action:@selector(cancelShareBtnAction:) forControlEvents:UIControlEventTouchUpInside];
}

// 删除
- (void)deleteBtnAction:(UIButton *)sender{

}

// 取消最优
- (void)cancelBestBtnAction:(UIButton *)sender{
    
}

// 保存图片
- (void)storePicBtnAction:(UIButton *)sender{
    
}

// 分享
- (void)sharePicBtnAction:(UIButton *)sender{
    [UIView animateWithDuration:0.25 animations:^{
        self.selectAllView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        self.selectedFlag = NO;
    }];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.shareView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        self.sharedFlag = YES;
    }];
//    if (!self.sharedFlag) {
//        
//    }else{
//        [UIView animateWithDuration:0.25 animations:^{
//            self.shareView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
//        } completion:^(BOOL finished) {
//            self.sharedFlag = NO;
//        }];
//    }
}

// 分享 取消 不需要加flag？
- (void)cancelShareBtnAction:(UIButton *)sender{
    [UIView animateWithDuration:0.25 animations:^{
        self.shareView.frame = CGRectMake(0, self.view.frame.size.height*2, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        self.sharedFlag = NO;
    }];
//    if (self.sharedFlag) { // 分享视图取消
//        [UIView animateWithDuration:0.25 animations:^{
//            self.shareView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
//        } completion:^(BOOL finished) {
//            self.sharedFlag = NO;
//        }];
//    }
}


// 图片操作 取消
- (void)cancelBtnAction:(UIButton *)sender{
    if (self.selectedFlag) {
        [UIView animateWithDuration:0.25 animations:^{
            self.selectAllView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.selectedFlag = NO;
        }];
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (self.selectedFlag) { // 操作视图取消
        [UIView animateWithDuration:0.25 animations:^{
            self.selectAllView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.selectedFlag = NO;
        }];
    }else if (self.sharedFlag) { // 分享视图取消
        [UIView animateWithDuration:0.25 animations:^{
            self.shareView.frame = CGRectMake(0, self.view.frame.size.height*2, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.sharedFlag = NO;
        }];
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)backBtnAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

// 对照片更多操作
- (void)moreBtnAction:(UIButton *)sender{
    if (!self.selectedFlag) {
        [UIView animateWithDuration:0.25 animations:^{
            self.selectAllView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.selectedFlag = YES;
        }];
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            self.selectAllView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
        } completion:^(BOOL finished) {
            self.selectedFlag = NO;
        }];
    }
}

// 分享视图
- (void)loadShareView{
    self.shareView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height*2, self.view.frame.size.width, self.view.frame.size.height)];
    self.shareView.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x000000 alpha:0.6];
    [self.view addSubview:self.shareView];
    
    self.shareUnderV = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 210*matchH, self.view.frame.size.width, 160*matchH)];
    self.shareUnderV.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:0.8];
    [self.shareView addSubview:self.shareUnderV];
    
    UILabel *shareL = [[UILabel alloc]initWithFrame:CGRectMake(25*matchW, 14*matchH, 140, 14)];
    shareL.text = @"分享到";
    shareL.textColor = [RGBColorEncapsulation colorWithRGB:0x000000 alpha:14];
    shareL.font = [UIFont systemFontOfSize:14];
    [self.shareUnderV addSubview:shareL];
    
    self.weixinBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.weixinBtn.frame = CGRectMake(25*matchW, CGRectGetMaxY(shareL.frame) + 15*matchH, 60*matchW, 60*matchW);
    [self.weixinBtn setBackgroundImage:[UIImage imageNamed:@"icon_wechat"] forState:UIControlStateNormal];
    [self.shareUnderV addSubview:self.weixinBtn];
    
    UILabel *weixinL = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.weixinBtn.frame), CGRectGetMaxY(self.weixinBtn.frame) + 6*matchH, 60, 12)];
    weixinL.text = @"微信好友";
    weixinL.textColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:1];
    weixinL.font = [UIFont systemFontOfSize:12];
    weixinL.textAlignment = NSTextAlignmentCenter;
    [self.shareUnderV addSubview:weixinL];
    
    self.firentBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.firentBtn.frame = CGRectMake(CGRectGetMaxX(self.weixinBtn.frame)+28*matchW, CGRectGetMinY(self.weixinBtn.frame), 60*matchW, 60*matchW);
    [self.firentBtn setBackgroundImage:[UIImage imageNamed:@"icon_friends"] forState:UIControlStateNormal];
    [self.shareUnderV addSubview:self.firentBtn];
    
    UILabel *firentL = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.firentBtn.frame), CGRectGetMaxY(self.firentBtn.frame) + 6*matchH, 60, 12)];
    firentL.text = @"朋友圈";
    firentL.textColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:1];
    firentL.font = [UIFont systemFontOfSize:12];
    firentL.textAlignment = NSTextAlignmentCenter;
    [self.shareUnderV addSubview:firentL];
    
    self.qqFriendBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.qqFriendBtn.frame = CGRectMake(CGRectGetMaxX(self.firentBtn.frame)+28*matchW, CGRectGetMinY(self.weixinBtn.frame), 60*matchW, 60*matchW);
    [self.qqFriendBtn setBackgroundImage:[UIImage imageNamed:@"icon_qq"] forState:UIControlStateNormal];
    [self.shareUnderV addSubview:self.qqFriendBtn];
    
    UILabel *qqFriendL = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.qqFriendBtn.frame), CGRectGetMaxY(self.firentBtn.frame) + 6*matchH, 60, 12)];
    qqFriendL.text = @"QQ好友";
    qqFriendL.textColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:1];
    qqFriendL.font = [UIFont systemFontOfSize:12];
    qqFriendL.textAlignment = NSTextAlignmentCenter;
    [self.shareUnderV addSubview:qqFriendL];
    
    self.qqSpaceBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.qqSpaceBtn.frame = CGRectMake(CGRectGetMaxX(self.qqFriendBtn.frame)+28*matchW, CGRectGetMinY(self.weixinBtn.frame), 60*matchW, 60*matchW);
    [self.qqSpaceBtn setBackgroundImage:[UIImage imageNamed:@"icon_qzone"] forState:UIControlStateNormal];
    [self.shareUnderV addSubview:self.qqSpaceBtn];
    
    UILabel *qqSpaceL = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.qqSpaceBtn.frame), CGRectGetMaxY(self.firentBtn.frame) + 6*matchH, 60, 12)];
    qqSpaceL.text = @"QQ空间";
    qqSpaceL.textColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:1];
    qqSpaceL.font = [UIFont systemFontOfSize:12];
    qqSpaceL.textAlignment = NSTextAlignmentCenter;
    [self.shareUnderV addSubview:qqSpaceL];
    
    self.cancelShareBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.cancelShareBtn.frame = CGRectMake(0, 210*matchH - 50*matchH, self.view.frame.size.width, 50*matchH);
    self.cancelShareBtn.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:1];
    [self.cancelShareBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelShareBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x000000 alpha:1] forState:UIControlStateNormal];
    self.cancelShareBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    self.cancelShareBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.shareUnderV addSubview:self.cancelShareBtn];
}

// 加载更多操作视图
- (void)loadSelectView{
    
    self.selectAllView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
    self.selectAllView.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x000000 alpha:0.6];
    [self.view addSubview:self.selectAllView];
    
    self.selectView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 256*matchH, self.view.frame.size.width, 256*matchH)];
    self.selectView.backgroundColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:0.8];
    [self.selectAllView addSubview:self.selectView];
    
    self.deleteBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.deleteBtn.frame = CGRectMake(0, 0, self.view.frame.size.width, 50*matchH);
    [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xff6c00 alpha:1] forState:UIControlStateNormal];
    self.deleteBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.selectView addSubview:self.deleteBtn];
    
    UIView *fill1V = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.deleteBtn.frame), self.view.frame.size.width, 1)];
    fill1V.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:0.5];
    [self.selectView addSubview:fill1V];
    
    self.cancelBestBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.cancelBestBtn.frame = CGRectMake(0, CGRectGetMaxY(self.deleteBtn.frame) + 1, self.view.frame.size.width, 50*matchH);
    [self.cancelBestBtn setTitle:@"取消最优" forState:UIControlStateNormal];
    [self.cancelBestBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x000000 alpha:1] forState:UIControlStateNormal];
    self.cancelBestBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.selectView addSubview:self.cancelBestBtn];
    
    UIView *fill2V = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.cancelBestBtn.frame), self.view.frame.size.width, 1)];
    fill2V.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:0.5];
    [self.selectView addSubview:fill2V];
    
    self.storePicBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.storePicBtn.frame = CGRectMake(0, CGRectGetMaxY(self.cancelBestBtn.frame) + 1, self.view.frame.size.width, 50*matchH);
    [self.storePicBtn setTitle:@"保存图片" forState:UIControlStateNormal];
    [self.storePicBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x000000 alpha:1] forState:UIControlStateNormal];
    self.storePicBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.selectView addSubview:self.storePicBtn];
    
    UIView *fill3V = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.storePicBtn.frame), self.view.frame.size.width, 1)];
    fill3V.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:0.5];
    [self.selectView addSubview:fill3V];
    
    self.sharePicBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.sharePicBtn.frame = CGRectMake(0, CGRectGetMaxY(self.storePicBtn.frame) + 1, self.view.frame.size.width, 50*matchH);
    [self.sharePicBtn setTitle:@"分享" forState:UIControlStateNormal];
    [self.sharePicBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x000000 alpha:1] forState:UIControlStateNormal];
    self.sharePicBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.selectView addSubview:self.sharePicBtn];
    
    self.fillView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.sharePicBtn.frame), self.view.frame.size.width, 9*matchH)];
    self.fillView.backgroundColor = [RGBColorEncapsulation colorWithRGB:0x555555 alpha:1];
    [self.selectView addSubview:self.fillView];
    
    self.cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.cancelBtn.frame = CGRectMake(0, CGRectGetMaxY(self.fillView.frame), self.view.frame.size.width, 50*matchH);
    [self.cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [self.cancelBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0x555555 alpha:1] forState:UIControlStateNormal];
    self.cancelBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    [self.selectView addSubview:self.cancelBtn];
}

- (void)loadPhotoV{
    self.photoV = [[UIImageView alloc]initWithFrame:CGRectMake(0, (self.view.frame.size.height - 64 - self.view.frame.size.width)/2 + 64, self.view.frame.size.width, self.view.frame.size.width)];
    self.photoV.image = [UIImage imageNamed:@"default_pic"];
    [self.view addSubview:self.photoV];
}

- (void)loadNavigationBg{
    self.navigationV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*matchW, 64)];
    self.navigationV.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_bg"]];
    [self.view addSubview:self.navigationV];
    
    self.navigationVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.view.frame.size.width - 100)/2), 31, 100, 18)];
    self.navigationVL.text = @"萝卜蹲";
    self.navigationVL.textAlignment = NSTextAlignmentCenter;
    self.navigationVL.textColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:1];
    self.navigationVL.font = [UIFont systemFontOfSize:18];
    [self.navigationV addSubview:self.navigationVL];
    
    self.navigationUnderVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.view.frame.size.width - 140)/2), CGRectGetMaxY(self.navigationVL.frame), 140, 15)];
    self.navigationUnderVL.text = @"12月14日 13:33";
    self.navigationUnderVL.textAlignment = NSTextAlignmentCenter;
    self.navigationUnderVL.textColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:1];
    self.navigationUnderVL.font = [UIFont systemFontOfSize:10];
    [self.navigationV addSubview:self.navigationUnderVL];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.backBtn.frame = CGRectMake(12*matchW, CGRectGetMinY(self.navigationVL.frame) + 2, 30, 30);
    [self.backBtn setBackgroundImage:[UIImage imageNamed:@"2left"] forState:UIControlStateNormal];
    [self.navigationV addSubview:self.backBtn];
    
    self.moreBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.moreBtn.frame = CGRectMake(self.view.frame.size.width - 30 - 12*matchW, CGRectGetMinY(self.backBtn.frame), 30, 30);
    [self.moreBtn setBackgroundImage:[UIImage imageNamed:@"point"] forState:UIControlStateNormal];
    [self.navigationV addSubview:self.moreBtn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
